package com.itsu.app.controller;

import com.itsu.api.controllerApi.CommentsControllerApi;
import com.itsu.app.service.AppCommentService;
import com.itsu.interfaces.service.CommentService;
import com.itsu.pojo.vo.PageResult;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommentsController implements CommentsControllerApi {

    @Autowired
    AppCommentService appCommentService;

    @Override
    public void addComments(String movementId, String comment) {
        appCommentService.addComments(movementId, comment);
    }

    @Override
    public ResponseEntity getComments(String movementId, Integer page, Integer pagesize) {
        PageResult pageResult = appCommentService.getComments(movementId, page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 评论点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity commentsLike(@PathVariable("id") String commentId) {
        Long commentLikeCount = appCommentService.commentsLike(new ObjectId(commentId));
        return ResponseEntity.ok(commentLikeCount);
    }

    /**
     * 评论取消点赞
     * @param commentId
     * @return
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity commentsDislike(@PathVariable("id") String commentId) {
        Long commentDislikeCount = appCommentService.commentsDislike(new ObjectId(commentId));
        return ResponseEntity.ok(commentDislikeCount);
    }
}
